#!/bin/sh

# setup
#qemu-system-x86_64 -machine accel=kvm -hda ./test.img -m 2048 -cdrom ./RHEL6.3-20120613.2-Server-x86_64-DVD1.iso -boot d -vnc 10.238.153.194:0 -monitor telnet:10.238.153.194:6666,server,nowait

qemu-system-x86_64 -machine accel=kvm -smp 8 -cpu Haswell -drive file=/home/kvm/vm/disk/centos.qcow2 -cdrom /home/kvm/vm/iso/CentOS-7-x86_64-Minimal-1511.iso -m 2048 -serial stdio -vnc 0.0.0.0:0 -monitor telnet:0.0.0.0:6666,server,nowait -boot d

# Run
#qemu-system-x86_64 -machine accel=kvm -hda ./test.img -m 2048 -serial stdio -vnc 10.238.153.194:0 -monitor telnet:10.238.153.194:6666,server,nowait
#qemu-system-x86_64 -machine accel=kvm -drive file=./test.img -m 2048 -serial stdio -vnc 10.238.153.194:0 -monitor telnet:10.238.153.194:6666,server,nowait
#qemu-system-x86_64 -machine accel=kvm -drive file=./test.img,format=raw -m 2048 -serial stdio -vnc 10.238.153.194:0 -monitor telnet:10.238.153.194:6666,server,nowait
#qemu-system-x86_64 -machine accel=kvm -smp 8 -cpu SandyBridge -drive file=./test.img,format=raw -m 2048 -serial stdio -vnc 10.238.153.111:0 -monitor telnet:10.238.153.111:6666,server,nowait
#qemu-system-x86_64 -machine accel=kvm -smp 8 -cpu Haswell -drive file=./test.raw,format=raw -m 2048 -serial stdio -vnc 10.238.153.111:0 -monitor telnet:10.238.153.111:6666,server,nowait
#qemu-system-x86_64 -machine accel=kvm -smp 8 -drive file=./test.raw,format=raw -drive file=./disk.qcow2 -m 2048 -serial stdio -vnc 10.238.153.111:0 -monitor telnet:10.238.153.111:6666,server,nowait
qemu-system-x86_64 -machine accel=kvm -smp 8 -drive file=./test.raw,format=raw -drive file=./disk.qcow2 -cdrom ./RHEL6.3-20120613.2-Server-x86_64-DVD1.iso -m 2048 -serial stdio -vnc 10.238.153.111:0 -monitor telnet:10.238.153.111:6666,server,nowait
qemu-system-x86_64 -machine accel=kvm -smp 8 -drive file=./test.raw,format=raw -drive file=./disk.qcow2 -m 2048 -serial stdio -vnc 10.238.153.111:0 -monitor telnet:10.238.153.111:6666,server,nowait


qemu-system-x86_64 -machine accel=kvm -smp 8 -cpu Haswell -drive file=/home/kvm/vm/disk/centos.qcow2 -cdrom /home/kvm/vm/iso/CentOS-7-x86_64-Minimal-1511.iso -m 2048 -serial stdio -vnc 0.0.0.0:0 -monitor telnet:0.0.0.0:6666,server,nowait


##############################################################
#NVDIMM
##############################################################
/home/chenyu/tool/qemu/bin/qemu-system-x86_64 -enable-kvm -machine pc,nvdimm -cpu kvm64 -m 1G,maxmem=100G,slots=100 -smp 4 -hda ubuntu.img -object memory-backend-file,share,id=mem1,mem-path=./nvdimm.img,size=4G -device nvdimm,memdev=mem1,id=nv1  -vnc 192.168.1.4:0 -monitor stdio


# 虚拟机网络配置
apt-get install uml-utilities
brctl addbr br0
tunctl -t tap0
tunctl -t tap1
brctl addif br0 tap0
brctl addif br0 tap1
ifconfig tap0 promisc up
ifconfig tap1 promisc up

ifconfig br0 up

/home/chenyu/tool/qemu/bin/qemu-system-x86_64 -enable-kvm -machine pc,nvdimm -cpu kvm64 -m 1G,maxmem=100G,slots=100 -smp 4 -hda ubuntu.img -object memory-backend-file,share,id=mem1,mem-path=./nvdimm.img,size=4G -device nvdimm,memdev=mem1,id=nv1  -vnc 192.168.1.4:0 -monitor stdio -netdev type=tap,id=eth0,ifname=tap0,script=no,downscript=no -device e1000,netdev=eth0,mac=12:03:04:05:06:08
/home/chenyu/tool/qemu/bin/qemu-system-x86_64 -enable-kvm -machine pc,nvdimm -cpu kvm64 -m 1G,maxmem=100G,slots=100 -smp 4 -hda ubuntu.img -object memory-backend-file,share,id=mem1,mem-path=./nvdimm.img,size=4G -device nvdimm,memdev=mem1,id=nv1  -vnc 192.168.1.4:0 -monitor stdio -netdev type=tap,id=eth0,ifname=tap0,script=no,downscript=no -device pcnet,netdev=eth0,mac=12:03:04:05:06:08





#######################################################
# NFV
#######################################################
# 安装
qemu-system-x86_64 -machine accel=kvm -smp 8 -cpu SandyBridge -drive file=/home/kvm/vm/disk/centos.qcow2 -cdrom /home/kvm/vm/iso/CentOS-7-x86_64-Minimal-1511.iso -m 2048 -serial stdio -vnc 10.100.16.162:0 -monitor telnet:10.100.16.162:6666,server,nowait
qemu-system-x86_64 -machine accel=kvm -smp 8 -cpu SandyBridge -drive file=/home/kvm/vm/disk/centos.qcow2 -cdrom /home/kvm/vm/iso/CentOS-7-x86_64-Minimal-1511.iso -m 2048 -serial stdio -vnc 0.0.0.0:0 -monitor telnet:0.0.0.0:6666,server,nowait
# 运行
qemu-system-x86_64 -machine accel=kvm -smp 8 -cpu SandyBridge -drive file=/home/kvm/vm/disk/centos.qcow2 -m 2048 -serial stdio -vnc 0.0.0.0:0 -monitor telnet:0.0.0.0:6666,server,nowait
# 网络
# 虚拟机网络配置
modprobe tun
brctl addddbr br0
tunctl -t tap0
ifconfig tap0 0 promisc up
ifconfig enp1s0f2 0 promisc up
brctl addif br0 tap0
brctl addif br0 enp1s0f2
ifconfig br0 192.168.1.162/24 up
dhclient br0

modprobe tun
tunctl -t tap0
ifconfig tap0 0 promisc up
brctl addif br0 tap0

#删除tap0
tunctl -d tap0

qemu-system-x86_64 -machine accel=kvm -smp 8 -cpu SandyBridge -drive file=/home/kvm/vm/disk/centos.qcow2 -m 2048 -serial stdio -vnc 0.0.0.0:0 -monitor telnet:0.0.0.0:6666,server,nowait -netdev type=tap,id=eth0,ifname=tap0,script=no,downscript=no -device e1000,netdev=eth0,mac=12:03:04:05:06:08
qemu-system-x86_64 -machine accel=kvm -smp 8 -drive file=/home/kvm/vm/disk/centos.qcow2 -m 2048 -serial stdio -vnc 0.0.0.0:0 -monitor telnet:0.0.0.0:6666,server,nowait -netdev type=tap,id=eth0,ifname=tap0,script=no,downscript=no -device e1000,netdev=eth0,mac=12:03:04:05:06:88

# VIRTIO 网络
modprobe virtio_pci
modprobe virtio_net
modprobe vhost
modprobe vhost_net
qemu-system-x86_64 -machine accel=kvm -smp 8 -drive file=/home/kvm/vm/disk/centos.qcow2 -m 2048 -serial stdio -vnc 0.0.0.0:0 -monitor telnet:0.0.0.0:6666,server,nowait -netdev type=tap,id=eth0,ifname=tap0,script=no,downscript=no -device virtio-net-pci,netdev=eth0,mac=12:03:04:05:06:88 
# IOthreads + virtio
qemu-system-x86_64 -machine accel=kvm -smp 8 -drive file=/home/kvm/vm/disk/centos.qcow2 -m 2048 -serial stdio -vnc 0.0.0.0:0 -monitor telnet:0.0.0.0:6666,server,nowait -netdev type=tap,id=eth0,ifname=tap0,script=no,downscript=no -device virtio-net-pci,netdev=eth0,mac=12:03:04:05:06:08  -object iothread,id=my-iothrea


#带VHOST
qemu-system-x86_64 -machine accel=kvm -smp 8 -drive file=/home/kvm/vm/disk/centos.qcow2 -m 2048 -serial stdio -vnc 0.0.0.0:0 -monitor telnet:0.0.0.0:6666,server,nowait -netdev type=tap,id=eth0,ifname=tap0,vhost=on,vhostforce=on,script=no,downscript=no -device virtio-net-pci,netdev=eth0,mac=12:03:04:05:06:08 
# VHOST+IOTHREADS
qemu-system-x86_64 -machine accel=kvm -smp 8 -drive file=/home/kvm/vm/disk/centos.qcow2 -m 2048 -serial stdio -vnc 0.0.0.0:0 -monitor telnet:0.0.0.0:6666,server,nowait -netdev type=tap,id=eth0,ifname=tap0,vhost=on,vhostforce=on,script=no,downscript=no -device virtio-net-pci,netdev=eth0,mac=12:03:04:05:06:08  -object iothread,id=my-iothrea

# VIRTIO 磁盘
modprobe virtio_blk
qemu-system-x86_64 -machine accel=kvm -smp 8 
 -m 2048 -serial stdio -vnc 0.0.0.0:0 -monitor telnet:0.0.0.0:6666,server,nowait -netdev type=tap,id=eth0,ifname=tap0,vhost=on,vhostforce=on,script=no,downscript=no -device virtio-net-pci,netdev=eth0,mac=12:03:04:05:06:08 

#超大内存
qemu-system-x86_64 -machine accel=kvm -smp 8 -drive if=none,file=/home/kvm/vm/disk/centos.qcow2,id=hd0 -device virtio-blk-pci,drive=hd0 -object memory-backend-file,id=mem1,mem-path=/home/kvm/vm/disk/memory.raw,size=100G -device pc-dimm,memdev=mem1,id=dimm1 -m 175G -serial stdio -vnc 0.0.0.0:0 -monitor telnet:0.0.0.0:6666,server,nowait -netdev type=tap,id=eth0,ifname=tap0,vhost=on,vhostforce=on,script=no,downscript=no -device virtio-net-pci,netdev=eth0,mac=12:03:04:05:06:08 

#直通虚拟机
qemu-system-x86_64 -machine accel=kvm -smp 8 -drive file=/home/kvm/vm/disk/centos.qcow2 -m 2048 -serial stdio -vnc 0.0.0.0:0 -monitor telnet:0.0.0.0:6666,server,nowait -net none
qemu-system-x86_64 -machine accel=kvm -smp 8 -drive file=/home/kvm/vm/disk/centos.qcow2 -m 2048 -serial stdio -vnc 0.0.0.0:0 -monitor telnet:0.0.0.0:6666,server,nowait -device kvm-pci-assign,host=05:00.3,id=lfdev0,addr=0x6 -net none


qemu-system-x86_64 -machine accel=kvm -smp 8 -drive file=/home/kvm/vm/disk/centos.qcow2 -m 2048 -serial stdio -vnc 0.0.0.0:0 -monitor telnet:0.0.0.0:6666,server,nowait -device kvm-pci-assign,host=81:00.1,id=lfdev0,addr=0x6 -net none



/usr/local/bin/qemu-system-x86_64 -machine accel=kvm -smp 8 -drive file=/home/kvm/vm/disk/centos.qcow2 -m 2048 -serial stdio -vnc 0.0.0.0:0 -monitor telnet:0.0.0.0:6666,server,nowait -device kvm-pci-assign,host=05:00.3,id=lfdev0,addr=0x8 -net none -boot d

/home/kvm/tools/qemu2.6/bin/qemu-system-x86_64 -machine accel=kvm -smp 8 -drive file=/home/kvm/vm/disk/centos.qcow2 -m 2048 -serial stdio -vnc 0.0.0.0:0 -monitor telnet:0.0.0.0:6666,server,nowait -device kvm-pci-assign,host=05:00.3,id=lfdev0,addr=0x8 -net none -boot d





#DPDK
export VM_NAME=Centos-vm
export GUEST_MEM=1024M
export QCOW2_IMAGE=/home/kvm/vm/disk/centos.qcow2
export VHOST_SOCK_DIR=/home/kvm/tools/ovs-dpdk/var/run/openvswitch/
qemu-system-x86_64 -name $VM_NAME -cpu host -enable-kvm -m $GUEST_MEM -object memory-backend-file,id=mem,size=$GUEST_MEM,mem-path=/dev/hugepages,share=on -numa node,memdev=mem -mem-prealloc -smp sockets=1,cores=2 -drive file=$QCOW2_IMAGE -chardev socket,id=char0,path=$VHOST_SOCK_DIR/dpdkvhostuser0 -netdev type=vhost-user,id=mynet1,chardev=char0,vhostforce -device virtio-net-pci,mac=00:00:00:00:00:01,netdev=mynet1,mrg_rxbuf=off -chardev socket,id=char1,path=$VHOST_SOCK_DIR/dpdkvhostuser1 -netdev type=vhost-user,id=mynet2,chardev=char1,vhostforce -device virtio-net-pci,mac=00:00:00:00:00:02,netdev=mynet2,mrg_rxbuf=off --nographic -snapshot


qemu-system-x86_64 -name $VM_NAME -cpu host -enable-kvm -m $GUEST_MEM -object memory-backend-file,id=mem,size=$GUEST_MEM,mem-path=/dev/hugepages,share=on -numa node,memdev=mem -mem-prealloc -smp sockets=1,cores=2 -drive file=$QCOW2_IMAGE -chardev socket,id=char0,path=$VHOST_SOCK_DIR/dpdkvhostuser0 -netdev type=vhost-user,id=mynet1,chardev=char0,vhostforce -device virtio-net-pci,mac=00:00:00:00:00:01,netdev=mynet1,mrg_rxbuf=off -chardev socket,id=char1,path=$VHOST_SOCK_DIR/dpdkvhostuser1 -netdev type=vhost-user,id=mynet2,chardev=char1,vhostforce -device virtio-net-pci,mac=00:00:00:00:00:02,netdev=mynet2,mrg_rxbuf=off --nographic -snapshot


qemu-system-x86_64 -cpu host -machine accel=kvm -smp 8 -drive file=/home/kvm/vm/disk/centos.qcow2 -m 2048 -serial stdio -vnc 0.0.0.0:0 -monitor telnet:0.0.0.0:6666,server,nowait -chardev socket,id=char0,path=/home/kvm/tools/ovs-dpdk/var/run/openvswitch/dpdkvhostuser0 -netdev type=vhost-user,id=mynet1,chardev=char0,vhostforce -device virtio-net-pci,mac=00:00:00:00:00:01,netdev=mynet1,mrg_rxbuf=off

qemu-system-x86_64 -cpu host -machine accel=kvm -smp 8 -drive file=/home/kvm/vm/disk/centos.qcow2 -m 2048 -serial stdio -vnc 0.0.0.0:0 -monitor telnet:0.0.0.0:6666,server,nowait -chardev socket,id=char0,path=/home/kvm/tools/ovs-dpdk/var/run/openvswitch/dpdkvhostuser0 -netdev type=vhost-user,id=mynet1,chardev=char0,vhostforce -device virtio-net-pci,mac=00:00:00:00:00:01,netdev=mynet1,mrg_rxbuf=off

qemu-system-x86_64 -name $VM_NAME -cpu host -enable-kvm -m $GUEST_MEM -object memory-backend-file,id=mem,size=$GUEST_MEM,mem-path=/dev/hugepages,share=on -numa node,memdev=mem -mem-prealloc -smp sockets=1,cores=2 -drive file=$QCOW2_IMAGE -chardev socket,id=char0,path=$VHOST_SOCK_DIR/dpdkvhostuser0 -netdev type=vhost-user,id=mynet1,chardev=char0,vhostforce -device virtio-net-pci,mac=00:00:00:00:00:01,netdev=mynet1,mrg_rxbuf=off -chardev socket,id=char1,path=$VHOST_SOCK_DIR/dpdkvhostuser1 -netdev type=vhost-user,id=mynet2,chardev=char1,vhostforce -device virtio-net-pci,mac=00:00:00:00:00:02,netdev=mynet2,mrg_rxbuf=off --nographic -snapshot


##############################################################################
# 启动大页
##############################################################################
# 2M大页
qemu-system-x86_64 -machine accel=kvm -smp 8 -drive file=/home/kvm/vm/disk/centos.qcow2 -m 512 -serial stdio -vnc 0.0.0.0:0 -monitor telnet:0.0.0.0:6666,server,nowait -object memory-backend-file,id=ram-node0,prealloc=yes,mem-path=/dev/hugepages/,share=yes,size=536870912,host-nodes=0,policy=bind
#1G大页
qemu-system-x86_64 -machine accel=kvm -smp 8 -drive file=/home/kvm/vm/disk/centos.qcow2 -m 1024 -serial stdio -vnc 0.0.0.0:0 -monitor telnet:0.0.0.0:6666,server,nowait -object memory-backend-file,id=ram-node0,prealloc=yes,mem-path=/mnt/hugepages-1048576/,share=yes,size=1073741824,host-nodes=0,policy=bind

 
 



